package com.briup.app06.service.impl;
        import com.briup.app06.bean.UserInfo;
        import com.briup.app06.bean.UserInfoExample;
        import com.briup.app06.dao.UserInfoMapper;
        import com.briup.app06.service.IUserInfoService;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Service;
        import org.springframework.util.StringUtils;

        import javax.annotation.Resource;
        import java.util.List;

@Service
public class UserInfoServiceImpl implements IUserInfoService {

    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public List<UserInfo> query(String realname,String gender) {
        // 模板
        UserInfoExample example = new UserInfoExample();
        if(!StringUtils.isEmpty(realname)){
            example.createCriteria().andRealnameLike("%"+realname+"%");
        }

        if(!StringUtils.isEmpty(gender)){
            example.createCriteria().andGenderEqualTo(gender);
        }
        List<UserInfo> list = userInfoMapper.selectByExample(example);
        return list;
    }


    @Override
    public void saveOrUpdate(UserInfo userInfo) {
        // 如果userInfo中存在id属性，表示更新；否则保存
        if(userInfo.getId() == null){
            userInfoMapper.insert(userInfo);
        } else {
            userInfoMapper.updateByPrimaryKey(userInfo);
        }

    }

    @Override
    public void deleteById(long id) {
        userInfoMapper.deleteByPrimaryKey(id);
    }
}


